/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Remuneraciones.view;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 18472014-0
 */
public class Parametros extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
         List errorMsgs = (List) request.getAttribute("error");
         String DT = request.getParameter("DT");
           String CF = request.getParameter("CF");
             String HE = request.getParameter("HE");
               String SB = request.getParameter("SB");
         
        try {
            /*
             * TODO output your page here. You may use following sample code.
             */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Parametros</title>");            
            out.println("</head>");
            out.println("<body>");
               if(errorMsgs!=null){
            out.println("<h2>Reporte de Error</h2>");
            
            out.println("<font color='red'>Por favor corrija los siguientres errres:");
            out.println("<ul>");
            Iterator items = errorMsgs.iterator();
            while ( items.hasNext() ) {
            String message = (String) items.next();
            out.println("  <li>" + message + "</li>");
            }
            out.println("</ul>");
            out.println("vuelva e intentelo nuevamente.");
            out.println("</font>");
            }
            out.println("<form action='Calculo.do' method='POST'>");
            out.println("DT:<input type='text' name='DT'");
            if(DT==null){
            DT="";
            }
            
            out.println("value='"+DT+"'><br/> ");
            
            
            
            out.println("SB:<input type='text' name='SB'");
            if(SB==null){
            SB="";
            }
            
            out.println("value='"+SB+"' ><br/>");
            
            
            
            out.println("HE:<input type='text' name='HE'");
            if(HE==null){
            HE="";
            }
            
            out.println("value='"+HE+"' ><br/>");
            
            
            
            out.println("CF:<input type='text' name='CF'");
            
            if(CF==null){
            CF="";
            }
            
            out.println("value='"+CF+"' ><br/>");
            
            
            
             out.println("CIUDADES:<select name='ciudades'value=''>");
             
             
             
             for (int i=0; i<Lista.length; i++){
            out.println("<option value='"+Lista[i]+"'");
            out.println(">"+Lista[i]+"</option>");
            }
            out.println("</select>");
             out.println("<input type ='submit' value='enviar'/>");         
            out.println("</form>");
            out.println("<h1>Servlet Parametros at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }
 
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>


private String[] Lista = null;
    
    //Crear metodo init
    
    @Override
    public void init() throws ServletException{
        
        String lista_ciudad = getInitParameter("lista-ciudad");
        if (lista_ciudad == null){
            lista_ciudad = "Arica, Iquique, Calama,Concepcion,Temuco,Valdivia,Puerto montt";
        }
        Lista = lista_ciudad.split(",");
    }

}
